﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Peer
{
    internal class NotifyLock<T>
    {
        private readonly ManualResetEvent manualResetEvent;
        public NotifyLock()
        {
            manualResetEvent = new ManualResetEvent(false);
        }

        public bool Wait(int millisecondsTimeout)
        {
            return manualResetEvent.WaitOne(millisecondsTimeout);
        }

        public T Value { get; set; }

        public void Notify(T value)
        {
            Value = value;
            manualResetEvent.Set();
        }

    }
}
